<template>
	<div class="p_20 indexBanner">
		<el-dialog :visible.sync="isShow" :close-on-click-modal="false" @close="closeDialog">
			<el-divider></el-divider>
			<el-form :model="form" label-width="80px">
				<el-form-item label="标题">
					<el-input v-model="form.title" class="w_400"></el-input>
				</el-form-item>
				
				<UploadImg ref="UploadImg" :upImg = "upImg"></UploadImg>
				
				<el-form-item label="文本一">
					<el-input v-model="form.text1" class="w_400"></el-input>
				</el-form-item>
				<el-form-item label="文本二">
					<el-input v-model="form.text2" class="w_400"></el-input>
				</el-form-item>
				<el-form-item label="文本三">
					<el-input v-model="form.text3" class="w_400"></el-input>
				</el-form-item>
				<el-form-item label="文本四">
					<el-input v-model="form.text4" class="w_400"></el-input>
				</el-form-item>
				<el-form-item label="排序">
					<el-input v-model="form.sort" class="w_250"></el-input>
					<span>（数字越大越靠前）</span>
				</el-form-item>
				<el-form-item label="更多链接">
					<el-input v-model="form.url" class="w_400"></el-input>
					<span>（请将http://一并填入）</span>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeDialog">取 消</el-button>
				<el-button type="primary" @click="submit">确 定</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				isShow: false,
				
				form: {
					id:'',
					title:'',
					file:'',
					sort:0,
					text1:'',
					text2:'',
					text3:'',
					text4:'',
					language:0,
					url:''
				},
				upImg:{
					label: '图片',
					imageUrl: '',
					name: 'file',
					width: '61',
					height: '61',
					file: ''
				},

				//图片上传
				imageUrl: '',
				// dialogVisible: false,
				// disabled: false
			}
		},
		methods: {
			//提交
			submit(){
				console.log(this.form)
				let params = new FormData();
				
				params.append('id', this.form.id);
				params.append('title', this.form.title);
				params.append('sort', this.form.sort);
				params.append('text1', this.form.text1);
				params.append('text2', this.form.text2);
				params.append('text3', this.form.text3);
				params.append('text4', this.form.text4);
				params.append('url', this.form.url);
				params.append('language', this.$store.getters.getLanguage);
				
				if(this.upImg.file) {
					params.append('file', this.upImg.file);
				}
				
				if(this.form.id) {
					this.edit(params);
				}
			},
			
			
			//新增
			add(params){
				this.axiosGets('index/homepage/banner_add', params , res => {
					if(res.data.code === 0) {
						this.msgSuccess(res.data.msg);
						this.$parent.getTableData();
						this.isShow = false;
					}
				})
			},
			
			//编辑
			edit(params) {
				this.axiosPostFile('MainIndex/areaEdit', params , res => {
					if(res.data.code === 0) {
						this.msgSuccess(res.data.massage);
						this.$parent.getTableData();
						this.isShow = false;
					}
				})
			},


			
			//关闭窗口 清空数据
			closeDialog(){
				this.form = {
					id:'',
					title:'',
					file:'',
					sort:0,
					text1:'',
					text2:'',
					text3:'',
					text4:'',
					language:0,
					url:''
				}
				this.upImg={
					label: '图片',
					imageUrl: '',
					name: 'file',
					width: '61',
					height: '61',
					file: ''
				},
				this.imageUrl = ''
				this.isShow = false;
			}
		}
	}
</script>

<style scoped>

</style>
